/*
* Poppy Game Engine - https://pgetemplate.googlecode.com/svn/
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* Copyright (c) 2008 Poppy
*/

#define APPLICATION_NAME "TestDemo"

#include "TestDemo.h"
#include "CTime.h"
#include "CFPSTimer.h"
#include "CPSPDriver.h"
#include "CFileStream.h"
#include "IImageLoader.h"
#include "CRenderer.h"

using namespace PGESystem;
using namespace PGERenderer;
using namespace PGEMath;

int main()
{
	
	INIT;
	
	CTime* pTime = PGENew CTime();
	ITimer* pFPS = PGENew CFPSTimer( 200.0f );

	pTime->InitTime();

	pTime->AddTimer( &pFPS );

	FillableRect rects[2] = { FillableRect(0, 0, 100, 100, PGE_RGB(255, 0, 0)), FillableRect(100, 100, 100, 100, PGE_RGB(0, 255, 0)) };

	FillablePoint points[2] = { FillablePoint(50, 50, PGE_RGB(255, 0, 0)), FillablePoint(150, 150, PGE_RGB(0, 255, 0)) };

	FillableLine lines[2] = { FillableLine(10, 10, 400, 250, PGE_RGB(255, 255, 0)), FillableLine(10, 250, 400, 10, PGE_RGB(255, 255, 0)) };

	SPOINT_I tt[4] = { SPOINT_I( 200, 10 ), SPOINT_I( 250, 10 ), SPOINT_I( 250, 100 ), SPOINT_I( 150, 100 ),  };
	
	PointList pointss( tt, PGE_RGB(255, 0, 0), 4 );

	const float* fps = ((CFPSTimer*)pFPS)->GetFps();
	
	//SceCtrlData pad;

	//sceCtrlSetSamplingCycle(0);
	//sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
	
	CRenderer* renderer = CRenderer::GetInstance();

	renderer->InitGraphicSystem();	
	
	unsigned int color = PGE_RGB(45, 50, 170);
	
	renderer->ClearState(CLEAR_COLOR, color);
	while(1)
	{
		
		if(renderer->BeginScene())
		{
			//renderer->DrawRect(rects[0].rect,rects[0].color);
			//renderer->DrawRect(rects[1].rect,rects[1].color);
			renderer->DrawRectList(rects, 2);
			renderer->DrawPointList(points, 2);
			renderer->FillPolygon(pointss);
			renderer->DrawLineList( lines, 2 );
			renderer->EndScene();
		}
		pTime->Time();
		renderer->Present();
		#ifdef WIN32
		//printf("FPS: %.0f\n", *fps);
		#endif
		#ifdef PSP
		printf("FPS: %.0f", *fps);
		#endif
		
		
	}
	
	renderer->TermGraphicSystem();
	
	CRenderer::Release();
	
	pTime->DestoryTime();

	PGEDelete pTime;
	
	WAIT;
	EXIT;
	return 0;
}
